home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Texto y fuentes / TextOnBaseline / TextOnBaseline.cs next >
Encoding:
Text File  |  2002-07-01  |  1.4 KB  |  44 lines

  1. //---------------------------------------------
  2. // TextOnBaseline.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class TextOnBaseline: PrintableForm
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new TextOnBaseline());
  13.      }
  14.      public TextOnBaseline()
  15.      {
  16.           Text = "Texto en lφnea de base";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           float yBaseline = cy / 2;
  21.           Pen   pen       = new Pen(clr);
  22.  
  23.                // Dibuja la lφnea de base en el centro del ßrea cliente.
  24.  
  25.           grfx.DrawLine(pen, 0, yBaseline, cx, yBaseline);
  26.  
  27.                // Crea una fuente de 144 puntos.
  28.  
  29.           Font font = new Font("Times New Roman", 144);
  30.  
  31.                // Obtiene y calcula algunas mΘtricas.
  32.  
  33.           float cyLineSpace = font.GetHeight(grfx);
  34.           int   iCellSpace  = font.FontFamily.GetLineSpacing(font.Style);
  35.           int   iCellAscent = font.FontFamily.GetCellAscent(font.Style);
  36.           float cyAscent    = cyLineSpace * iCellAscent / iCellSpace;
  37.  
  38.                // Muestra el texto en la lφnea de base.
  39.  
  40.           grfx.DrawString("Lφnea de base", font, new SolidBrush(clr),
  41.                           0, yBaseline - cyAscent);
  42.      }
  43. }
  44.